package com.crm.controller;

import com.crm.common.result.ResultVO;
import com.crm.common.result.TableDataInfo;
import com.crm.DTO.CoursesDto;
import com.crm.service.CoursesService;
import com.crm.entity.Courses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 2025/9/4 11:11
 * 注释：
 */
@RequestMapping("/clues/course")
@RestController
@Tag(name = "课程管理接口")
@Slf4j
public class CoursesController {

    @Autowired
    private CoursesService coursesService;

    /**
     * 查询学科下对应的课程列表
     */
    @GetMapping("/listselect")
    public ResultVO<List<Courses>> listCoursesBySuibject(Integer subject) {
        log.info("查询学科下对应的课程列表");
        List<Courses> list = coursesService.listCoursesBySubject(subject);
        return ResultVO.success(list);
    }


    /**
     * 课程列表(分页查询)
     *
     * @param coursesDto
     * @return
     */
    @GetMapping("list")
    public TableDataInfo<Courses> searchCoursesVo(CoursesDto coursesDto) {
        log.info("课程列表(分页查询)");
        return coursesService.searchCourses(coursesDto);
    }

    /**
     * 删除课程
     */
    @DeleteMapping("/{coursesId}")
    public ResultVO deleteCourses(@PathVariable String coursesId) {
        log.info("删除课程{}", coursesId);
        coursesService.deleteCourses(coursesId);
        return ResultVO.success();
    }

    /**
     * 查询课程
     */
    @GetMapping("/{coursesId}")
    public ResultVO<Courses> getCourses(@PathVariable String coursesId) {
        log.info("查询课程{}", coursesId);
        return coursesService.getCourses(coursesId);
    }


    /**
     * 修改课程
     */
    @PutMapping
    public ResultVO updateCourses(@RequestBody CoursesDto coursesDto) {
        log.info("修改课程{}", coursesDto);
        coursesService.updateCourses(coursesDto);
        return ResultVO.success();
    }

    /**
     * 新增课程
     */
    @PostMapping
    public ResultVO saveCourses(@RequestBody CoursesDto coursesDto) {
        log.info("新增课程{}", coursesDto);
        coursesService.saveCourses(coursesDto);
        return ResultVO.success();
    }
}


